package com.sky.mapper;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrdersMapper {
    //保存订单  3-2 保存到数据库(订单表中)  主键返回
    void save(Orders orders);

    // 根据订单号查询
    @Select("select * from orders where number = #{orderNumber}")
    Orders findByNumber(String orderNumber);

    // 修改订单信息
    void update(Orders orders);

    // 2.条件查询List<OederVO>查询 (查询订单)
    List<OrderVO> findList(OrdersPageQueryDTO ordersPageQueryDTO);

    // 3-3 根据id查询订单
    @Select("select * from orders where id = #{id}")
    OrderVO findById(Long id);

    // 统计订单状态
    @Select("select count(*) from orders where status = #{status}")
    Integer findCountStatus(Integer status);

    // 查询订单状态和下单时间
    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> findByStatusAndOrderTime(Integer status, LocalDateTime time);
}
